<?php
abstract class system_view_helper_formElement extends system_view_helper_htmlElement {
	
	protected function _getInfo($name, $value = null, $attribs = null, $options = null) {
		$info = array('name' => is_array($name) ? '' : $name, 'id' => is_array($name) ? '' : $name, 'value' => $value, 'attribs' => $attribs, 'options' => $options);
		
		if(is_array($name)) {
			foreach($info as $key => $val) {
				if(isset($name[$key])) {
					$info[$key] = $name[$key];
				}
			}
			if(null === $attribs) {
				$attribs = $info['attribs'];
			}
		}
		
		$attribs = (array) $attribs;		
		if(array_key_exists('id', $attribs)) {
			$info['id'] = (string) $attribs['id'];
		} else {
			if('' !== $info['name']) {
				$info['id'] = trim(strtr($info['name'], array('[' => '-', ']' => '')), '-');
			}
		}
		
		if(array_key_exists('name', $attribs) && is_null($attribs['name'])) {
			unset($attribs['name']);
		}
		
		if(array_key_exists('name', $attribs) && $attribs['name'] != $info['name']) {
			$info['name'] = $attribs['name'];
		}
		
		if(array_key_exists('value', $attribs)) {
			$info['value'] = $this->view->escape($attribs['value']);
			unset($attribs['value']);
		}
		
		foreach($info as $key => $val) {
			if(array_key_exists($key, $attribs)) {
				unset($attribs[$key]);
			}
		}
		$info['attribs'] = $attribs;
		return $info;
	}
	
	protected function _hidden($name, $value = null, $attribs = null) {
		return '<input type="hidden"' . ' name="' . $this->view->escape($name) . '"' . ' value="' . $this->view->escape($value) . '"' . $this->_htmlAttribs($attribs) . $this->getClosingBracket();
	}
}
